package com.finger.crowd.mvc.interceptor;

import com.finger.crowd.constant.CrowdConstant;
import com.finger.crowd.entity.Admin;
import com.finger.crowd.exception.AccessForbiddenException;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginIntercepter extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 使用springsercurity之后就不用自定义拦截器了
        // 获取session
        //HttpSession session = request.getSession();

        //从session中取得登录得用户
        //Admin user = (Admin) session.getAttribute(CrowdConstant.ATTR_NAME_LOGIN_ADMIN);

        // 判断用户是否为null
        //if (user == null) {
        //    throw new AccessForbiddenException(CrowdConstant.MESSAGE_ACCESS_FORBIDDEN);
        //}

        return true;
    }
}
